package view;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;


public class Principal extends JFrame {

	private JPanel contentPane;

	/**
	 * Create the frame.
	 */
	public Principal(String rol) {
		setTitle("MLG");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 254, 371);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		
		JButton Mercados = new JButton("Mercados");
		Mercados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MercadosActionPerformed(evt);
            }
        });
		
		JButton Compaias = new JButton("Compa\u00F1ias");
		Compaias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CompaiasActionPerformed(evt);
            }
        });
		
		JButton Acciones = new JButton("Acciones");
		Acciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AccionesActionPerformed(evt);
            }
        });
		
		JButton PreciosAcciones = new JButton("Precios Acciones");
		PreciosAcciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	PreciosAccionesActionPerformed(evt);
            }
        });
		
		JButton VisualizadorEstadisticas = new JButton("Visualizador estadisticas");
		VisualizadorEstadisticas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	VisualizadorEstadisticasActionPerformed(evt);
            }
        });
		
		JButton VisualizadorDeRetornos = new JButton("Visualizador de retornos");
		VisualizadorDeRetornos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	VisualizadorDeRetornosActionPerformed(evt);
            }
        });
		
		JButton btnSalir = new JButton("Salir");
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(42)
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
								.addComponent(VisualizadorDeRetornos, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(VisualizadorEstadisticas, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(PreciosAcciones, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(Acciones, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(Compaias, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(Mercados, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(81)
							.addComponent(btnSalir)))
					.addContainerGap(26, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(26)
					.addComponent(Mercados)
					.addGap(18)
					.addComponent(Compaias)
					.addGap(18)
					.addComponent(Acciones)
					.addGap(18)
					.addComponent(PreciosAcciones)
					.addGap(18)
					.addComponent(VisualizadorEstadisticas)
					.addGap(18)
					.addComponent(VisualizadorDeRetornos)
					.addPreferredGap(ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
					.addComponent(btnSalir)
					.addContainerGap())
		);
		panel.setLayout(gl_panel);
		
		if(rol.equals("Analista 2")){
			Mercados.setEnabled(false);
			PreciosAcciones.setEnabled(false);
			VisualizadorDeRetornos.setEnabled(false);
		}
		
		if(rol.equals("Tecnico")){
			Mercados.setEnabled(false);
			PreciosAcciones.setEnabled(false);
			VisualizadorDeRetornos.setEnabled(false);
		}
		
	}

	protected void VisualizadorDeRetornosActionPerformed(ActionEvent evt) {
		VisualizadorRetornos retornos = new VisualizadorRetornos();
		retornos.setLocationRelativeTo(null);
        retornos.setVisible(true);
        this.dispose();
	}

	protected void VisualizadorEstadisticasActionPerformed(ActionEvent evt) {
		VisualizadorEstadisticas estadisticas = new VisualizadorEstadisticas();
		estadisticas.setLocationRelativeTo(null);
        estadisticas.setVisible(true);
        this.dispose();
	}

	protected void PreciosAccionesActionPerformed(ActionEvent evt) {
		PreciosAcciones acciones = new PreciosAcciones();
		acciones.setLocationRelativeTo(null);
        acciones.setVisible(true);
        this.dispose();
	}

	protected void AccionesActionPerformed(ActionEvent evt) {
		Acciones acciones = new Acciones();
		acciones.setLocationRelativeTo(null);
		acciones.setVisible(true);
		this.dispose();
	}

	protected void CompaiasActionPerformed(ActionEvent evt) {
		Companias companias = new Companias();
		companias.setLocationRelativeTo(null);
		companias.setVisible(true);
		this.dispose();
	}

	protected void MercadosActionPerformed(ActionEvent evt) {
		Mercados mercados = new Mercados();
		mercados.setLocationRelativeTo(null);
		mercados.setVisible(true);
		this.dispose();
	}

}
